<template>
  <div class="article-manager">
    <div class="i-layout-page-header">
      <div class="i-layout-page-header">
        <span class="ivu-page-header-title">{{ title }}</span>
        <div>
        </div>
      </div>
    </div>
    <Card :bordered="false" dis-hover class="ivu-mt fromBox">
      <form-create :option="option" :rule="rules" @on-submit="onSubmit" v-if="rules.length !== 0"></form-create>
      <Spin size="large" fix v-if="spinShow"></Spin>
    </Card>
  </div>
</template>

<script>
import formCreate from '@form-create/iview';
import { headerListApi, dataFromApi } from '@/api/setting';
import request from '@/libs/request';
import { getLogo } from '@/api/common';
export default {
  name: 'setting_setSystem',
  components: { formCreate: formCreate.$form() },
  data() {
    return {
      rules: [],
      option: {
        form: {
          labelWidth: 185,
        },
        submitBtn: {
          col: {
            span: 3,
            push: 3,
          },
        },
        global: {
          upload: {
            props: {
              onSuccess(res, file) {
                if (res.status === 200) {
                  file.url = res.data.src;
                } else {
                  this.$Message.error(res.msg);
                }
              },
            },
          },
          frame: {
            props: {
              closeBtn: false,
              okBtn: false,
            },
          },
        },
      },
      spinShow: false,
      FromData: null,
      currentTab: '',
      headerList: [],
      headerChildrenList: [],
      childrenId: '',
      title: '',
    };
  },
  created() {
    this.getFrom();
  },
  watch: {
    $route(to, from) {
      this.headerChildrenList = [];
      this.getFrom();
    },
    childrenId() {
      this.getFrom();
    },
  },
  methods: {
    childrenList(index) {
      
    },
    // 表单
    getFrom() {
		let url = 'platform/edit';
		this.spinShow = true;
		dataFromApi({}, url)
		  .then(async (res) => {
		    this.spinShow = false;
		    if (res.data.status === false) {
		      return this.$authLapse(res.data);
		    }
		    this.FromData = res.data;
		    this.rules = res.data.rules;
		    this.title = res.data.title;
		  })
		  .catch((res) => {
		    this.spinShow = false;
		    this.$Message.error(res.msg);
		  });
    },
    // 提交表单 group
    onSubmit(formData) {
      request({
        url: this.FromData.action,
        method: this.FromData.method,
        data: formData,
      })
        .then((res) => {
          this.getAdminTitle();
          this.$Message.success(res.msg);
        })
        .catch((res) => {
          this.$Message.error(res.msg);
        });
    },
    getAdminTitle() {
      getLogo().then((res) => {
        // localStorage.setItem('ADMIN_TITLE', res.data.site_name);
        localStorage.setItem('ADMIN_TITLE', '后台管理');
      });
    },
  },
};
</script>

<style scoped lang="stylus">
.ivu-tabs {
  margin-bottom: 18px;
}

.fromBox {
  min-height: 600px;
}
</style>
